<template>
  <h2>测试十，customRef 测试自定义的Ref</h2>
  <input v-model="keyword"/>
  <h3>文本内容：{{ keyword }}</h3>
</template>

<script>
import {ref,customRef,triggerRef} from "vue";
export default {
  name: "CustomRefTest",
  setup(){
    // let keyword=ref("")
    function myRef(obj){
      return customRef((track, trigger)=>{
        return {
          get(){
            console.log("读值",obj)
            track()
            return obj;
          },
          set(newvalue){
            console.log("修改值",obj,newvalue)
            setTimeout(()=>{
              obj=newvalue
              trigger()
            },500)
          },
        }
      })
    }
    let keyword=myRef("")
    return {keyword}
  }
}
</script>